import * as bm from "/js/baseModule.js";

export class Module extends bm.baseModule {
    constructor(view) {
        super(view);
        let that = this;
        let dom = this.find('.FeedbackDemand_vue')[0];
        new Vue({
            el: dom,
            data: globalData,
        });

        /**
         * 如果是直接进入当前页面，则先loading一会儿，等数据回来
         */
        if (globalData.entryPage == 'project/FeedbackDemand') {
            setTimeout(funs.removeWelcome,300);
            this.find('.sendImgPending').removeClass('hide');
            let id = funs.qs('feedbackdemand');
            api.getDemandInfo({"id": id}, {
                succ: function (demand) {
                    $.extend(true, globalData.current_demand, demand);
                    that.find('.sendImgPending').addClass('hide');
                    that._init();
                },
                fail: function (json) {
                    //  如果是项目已被删除或者不存在
                    if (json.name = "41004002") {
                        funs.openModal('modules/modals/CommonModal.JS', function (mod) {
                            mod.setType(9);
                        })
                    } else {
                        funs.tip(json.msg, '', 'fail');
                        setTimeout(function () {
                            that._evt_goback();
                        }, 2000)
                    }
                }
            })
        }else{
            that._init();
        }
        //监听数据返回
        $(document).on('data_update', function () {
            // 如果是直接进入当前页面，且项目已被删除或者不存在，则回到项目大厅
            if (globalData.currPage == 'feedbackdemand' && globalData.current_demand.uid == '0000X') {
                //订单不可见
                funs.openModal('modules/modals/CommonModal.JS', function (mod) {
                    mod.setType(9);
                })
            }
        });
    }

    _init() {
        //feedback_status==2（审核中）或者feedback_status==3（成功）进入结果页
        if (globalData.current_demand.feedback_info.feedback_status == 2 || globalData.current_demand.feedback_info.feedback_status == 3) {
            location.hash = 'project/FeedbackDemand/FeedbackResult';
        }
    }

    /**查看该项目 */
    _evt_projectDetail() {
        let pro_info = globalData.current_demand;
        if (pro_info) {
            globalData.current_demand = pro_info;
            location.hash = 'demand?did='+pro_info.id;
        }
    }
}
